package com.ibeetl.admin.api.service;

import com.ibeetl.admin.api.dao.TravelGuideDao;
import com.ibeetl.admin.api.entity.Travel_guide;
import com.ibeetl.admin.api.web.query.TravelGuideQuery;
import com.ibeetl.admin.core.service.CoreBaseService;
import org.beetl.sql.core.page.PageRequest;
import org.beetl.sql.core.page.PageResult;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class TravelGuideService extends CoreBaseService<Travel_guide> {
    @Resource
    private TravelGuideDao travelGuideDao;

    public Long queryNewIdByUserId(Integer userId) {
        List<Long> list = travelGuideDao.queryNewIdByUserId(userId);
        if(list == null || list.size()<1) return null;
        return list.get(0);
    }

    public Travel_guide queryById(Long guideId) {
        return travelGuideDao.queryById(guideId);
    }

    public List<Travel_guide> queryByState(Long userId, Integer isValid) {
        return travelGuideDao.queryByState(userId,isValid);
    }

    public void audit(Travel_guide travelGuide) {
        travelGuide.setUpdateDt(new Date());
        travelGuide.setReviewDt(new Date());
        travelGuide.setReviewers("admin");
        travelGuideDao.audit(travelGuide);

    }
    public PageResult<Travel_guide> queryByCondition(TravelGuideQuery condition) {
        PageRequest pageRequest = condition.getPageRequest();
        Map params = condition.getPageParam();
        PageResult ret = travelGuideDao.queryByCondition(pageRequest, params);
        queryListAfter(ret.getList());
        return ret;
    }
}
